package requests

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/contracts/validation"
	"github.com/spf13/cast"
)

type DepartmentRequest struct {
	SiteID uint   `form:"site_id" json:"site_id"`
	No     string `form:"no" json:"no"`
	Name   string `form:"name" json:"name"`
	Status int    `form:"status" json:"status"`
	Remark string `form:"remark" json:"remark"`
	Pid    int    `form:"pid" json:"pid"`
}

func (r *DepartmentRequest) Authorize(ctx http.Context) error {
	return nil
}

func (r *DepartmentRequest) Rules(ctx http.Context) map[string]string {
	return map[string]string{
		"site_id": "required",
		"name":    "required",
		"status":  "required",
		"remark":  "required",
	}
}

func (r *DepartmentRequest) Messages(ctx http.Context) map[string]string {
	return map[string]string{
		"site_id.required": "site_id不能为空",
		"name.required":    "name不能为空",
		"status.required":  "status不能为空",
	}
}

func (r *DepartmentRequest) Attributes(ctx http.Context) map[string]string {
	return map[string]string{}
}

func (r *DepartmentRequest) PrepareForValidation(ctx http.Context, data validation.Data) error {
	val, exist := data.Get("status")
	if exist {
		r.Status = cast.ToInt(val)
	}
	pid, exist := data.Get("pid")
	if exist {
		r.Pid = cast.ToInt(pid)
	}
	return nil
}
